home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / Quotes 1.0 / src / document.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-09  |  2.0 KB  |  44 lines  |  [TEXT/KAHL]

  1. #pragma once
  2.  
  3. #include <Types.h>
  4.  
  5. const ResType TYPE_COOKIE = 'coOK'; // resource type of the cookie
  6. const short ID_COOKIE = 128; // resource number of the cookie
  7. const unsigned char COOKIE_SEPARATOR = '\r'; // return character
  8. struct CookieResource {
  9.     unsigned long size; // size of the data fork
  10.     int cFortune; // number of fortunes
  11.     long fortune[1]; // fortune[0] = 0, fortune[cFortune] = position of EOF
  12. };
  13. typedef struct CookieResource CookieResource;
  14.  
  15. enum CookieSave {SAVE_NO, SAVE_UPDATE, SAVE_NEW};
  16. typedef enum CookieSave CookieSave;
  17.  
  18. // cookie, the file that contains the fortunes
  19. // cookie, also the index resource in the file, and in memory
  20. // since resources are limited to 32K in size, the fortunes array is limited to 8190 entries
  21. // 8190 = (32768-8)/4, the last entry of fortunes points to EOF, one character past the end of the cookie
  22. const int LAST_FORTUNE = 8190;
  23. const long MAX_FORTUNE = 32767;
  24. class QuotesDocument {
  25. public:
  26.     int available(void) const; // return number of quotes
  27.      OSErr draw(int); // return the text of a quote
  28.      void discard(void); // when asked to save a cookie before closing, user said discard changes
  29.      Boolean save(void) const; // does this cookie need to be saved?
  30.      unsigned char *text(void) const; // return pointer to text of quote
  31.      QuotesDocument(FSSpec, OSErr&); // constructor
  32.      ~QuotesDocument(void); // destructor
  33. private:
  34.     FSSpec fsCookie; // file specification of the cookie data file
  35.     short selData; // file reference number of cookie data file
  36.     short selResource; // file reference number of cookie resource file
  37.     CookieSave selSave; // need to save cookie resource to file
  38.     CookieResource **hrsrcCookie; // handle to cookie resource
  39.     unsigned char *pchFortune; // handle to text of quote
  40.     OSErr scan(void); // read through the data of the cookie looking for repeated cookie separators
  41.     unsigned long resource_size(void) const; // size of the cookie resource
  42.     unsigned long current_size(void) const; // size of file referenced by selCookie
  43. };
  44.